<template>
	<view class="order-container">
		<!-- Navigation Bar -->
		<view class="nav-bar">
			<view class="nav-left" @click="goBack">
				<u-icon name="arrow-left" size="40rpx" color="#333"></u-icon>
			</view>
			<view class="nav-title">我的订单</view>
		</view>

		<!-- Course Cards -->
		<view class="course-list">
			<view class="course-card" v-for="(item, index) in courseList" :key="index">
				<view class="card-content">
					<view class="course-image">
						<u-image :src="item.url" mode="aspectFill" width="160rpx" height="160rpx" radius="12"></u-image>
					</view>
					<view class="course-info">
						<text class="course-name">{{item.courseName}}</text>
						<view class="info-row">
							<text class="label">课程类型：</text>
							<text class="value">{{item.courseType}}</text>
						</view>
						<view class="info-row">
							<text class="label">课程学时：</text>
							<text class="value">{{item.hours}}</text>
						</view>
						<view class="info-row">
							<text class="label">开课时间：</text>
							<text class="value">{{item.startTime}}</text>
						</view>
					</view>
				</view>
				<view class="card-footer">
					<view class="price">
						<text class="price-label">¥</text>
						<text class="price-value">{{item.price}}</text>
					</view>
					<view class="right-section">
						<view v-if="item.status === '已支付'" class="status-tag paid">
							{{item.status}}
						</view>
						<view v-else class="unpaid-section">
							<view class="status-tag unpaid">{{item.status}}</view>
							<u-button 
								type="error" 
								size="mini" 
								text="去支付" 
								@click="goPay(item)"
								class="pay-button">
							</u-button>
						</view>
					</view>
				</view>
			</view>
		</view>

		<!-- Empty State -->
		<view class="empty-state" v-if="courseList.length === 0">
			<u-empty mode="order" text="暂无订单"></u-empty>
		</view>
	</view>
</template>

<script>
	
	
	export default {
		data() {
			return {
				courseList: [
					{
						courseName: '高中数学辅导课程',
						courseType: '线下课',
						hours: '48课时',
						startTime: '2024-03-20',
						price: '2999',
						status: '未支付',
						url: '/static/course1.jpg'
					},
					{
						courseName: '英语口语提升班',
						courseType: '线上课',
						hours: '36课时',
						startTime: '2024-03-25',
						price: '1999',
						status: '已支付',
						url: '/static/course2.jpg'
					}
				]
			}
		},
		onLoad() {
			this.getOrderList()
		},
		methods: {
			getOrderList() {
				const data = {
					studentId: 1
				}
				getOrderList(data).then(res => {
					console.log(res)
					// this.courseList = res.data.orderList
				})
			},
			goBack() {
				uni.navigateBack()
			},
			goPay(course) {
				uni.navigateTo({
					url: `/pages/payment/payment?courseId=${course.id}&amount=${course.price}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.order-container {
	min-height: 100vh;
	background-color: #f8f8f8;
}

.nav-bar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	height: 88rpx;
	background-color: #fff;
	display: flex;
	align-items: center;
	padding: 0 30rpx;
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
	z-index: 100;
	
	.nav-left {
		padding: 20rpx;
		margin-left: -20rpx;
	}
	
	.nav-title {
		flex: 1;
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		margin-right: 88rpx; // 补偿左侧按钮的宽度，使标题居中
	}
}

.course-list {
	padding: 108rpx 20rpx 20rpx; // 顶部留出导航栏的空间
	.course-card {
		background-color: #fff;
		border-radius: 16rpx;
		padding: 24rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
		
		.card-content {
			display: flex;
			gap: 20rpx;
			margin-bottom: 20rpx;
			
			.course-image {
				flex-shrink: 0;
			}
			
			.course-info {
				flex: 1;
				min-width: 0;
				
				.course-name {
					font-size: 32rpx;
					font-weight: bold;
					color: #333;
					margin-bottom: 16rpx;
					display: block;
				}
				
				.info-row {
					display: flex;
					margin-bottom: 8rpx;
					
					&:last-child {
						margin-bottom: 0;
					}
					
					.label {
						font-size: 26rpx;
						color: #666;
						width: 140rpx;
					}
					
					.value {
						font-size: 26rpx;
						color: #333;
						flex: 1;
					}
				}
			}
		}
		
		.card-footer {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-top: 20rpx;
			border-top: 1px solid #eee;
			
			.price {
				display: flex;
				align-items: baseline;
				
				.price-label {
					font-size: 24rpx;
					color: #ff4d4f;
					margin-right: 4rpx;
				}
				
				.price-value {
					font-size: 36rpx;
					font-weight: bold;
					color: #ff4d4f;
				}
			}
			
			.right-section {
				display: flex;
				align-items: center;
				
				.unpaid-section {
					display: flex;
					align-items: center;
					gap: 12rpx;
					background-color: #fff1f0;
					padding: 4rpx 12rpx;
					border-radius: 24rpx;
					
					.status-tag {
						margin: 0;
						background: none;
						padding: 0;
						font-size: 24rpx;
					}
					
					.pay-button {
						margin: 0;
						
						:deep(.u-button) {
							height: 44rpx;
							font-size: 24rpx;
							padding: 0 16rpx;
							background-color: #ff4d4f;
							border: none;
						}
					}
				}
				
				.status-tag {
					padding: 6rpx 20rpx;
					border-radius: 20rpx;
					font-size: 24rpx;
					
					&.paid {
						background-color: #f6ffed;
						color: #52c41a;
					}
				}
			}
		}
	}
}

.empty-state {
	padding: 100rpx 0;
}
</style>
